﻿using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Unity.Mvc3;

using ASPNETMVC4Tutorial.Models;
using System.Web.Http;
using ASPNETMVC4Tutorial.Lib;

namespace ASPNETMVC4Tutorial
{
    public static class Bootstrapper
    {
        public static void Initialise()
        {
            var container = BuildUnityContainer();

            //Unity MVC resolver
            DependencyResolver.SetResolver(new Unity.Mvc3.UnityDependencyResolver(container));

            //Unity web api resolver
            GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);

        }

        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();

            // register all your components with the container here
            // it is NOT necessary to register your controllers
            container.RegisterType<ILogger, TextWriterLogger>();
            container.RegisterType<IProductRepository, ProductRepository>();
            return container;
        }
    }
}